<?php

/**
 * This is the model class for table "pedido".
 *
 * The followings are the available columns in table 'pedido':
 * @property integer $idpedido
 * @property string $descripcion
 * @property string $estado
 * @property double $monto_total
 * @property integer $USUARIO_idusuario
 *
 * The followings are the available model relations:
 * @property Mydb.usuario $uSUARIOIdusuario
 */
class Pedido extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Pedido the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pedido';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idpedido, USUARIO_idusuario', 'numerical', 'integerOnly'=>true),
			array('monto_total', 'numerical'),
			array('descripcion', 'length', 'max'=>500),
			array('estado', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idpedido, descripcion, estado, monto_total, USUARIO_idusuario', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'uSUARIOIdusuario' => array(self::BELONGS_TO, 'Mydb.usuario', 'USUARIO_idusuario'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idpedido' => 'Idpedido',
			'descripcion' => 'Descripcion',
			'estado' => 'Estado',
			'monto_total' => 'Monto Total',
			'USUARIO_idusuario' => 'Usuario Idusuario',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idpedido',$this->idpedido);
		$criteria->compare('descripcion',$this->descripcion,true);
		$criteria->compare('estado',$this->estado,true);
		$criteria->compare('monto_total',$this->monto_total);
		$criteria->compare('USUARIO_idusuario',$this->USUARIO_idusuario);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}